#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct node{
  int d,v,a,id;
  double et,ex;
}car[N];
bool cmp1(node a,node b){
  return a.d<b.d;
}
bool flag;
int T,n,m,L,V,d[N],v[N],a[N],p[N],road[N],pmx,x,y,num,lstx,lstc;
int main(){
  freopen("deteck.in","r",stdin);
  freopen("deteck.out","w",stdout);
  scanf("%d",&T);
  for(int t=1;t<=T;t++){
    memset(car,0,sizeof(car));
    memset(p,0,sizeof(p));
    pmx=0;
    lstx=L;
    num=0;
    scanf("%d",&n);
    scanf("%d",&m);
    scanf("%d",&L);
    scanf("%d",&V);
      for(int i=1;i<=n;i++){
        scanf("%d",&car[i].d);
        scanf("%d",&car[i].v);
        scanf("%d",&car[i].a);
        car[i].id=i;
      }
      for(int i=1;i<=m;i++)
        scanf("%d",&p[i]),pmx=max(pmx,p[i]);
      sort(car+1,car+n+1,cmp1);
      for(int i=1;i<=n;i++)
      if(car[i].d>pmx){
        num=i-1;
        break;
      }
      cout<<num<<endl<<m-1<<endl;
  }
  return 0;
}
